<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <div id="page">
        <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
        <%@include file='header_gerente.jsp' %>
            <div id="contents">
                <div id="tagline" class="clearfix">
                    <h1>Cadastro de Usuários</h1>
                        <form method="POST" action="Controladora?action=CadastrarUsuario" data-validate="parsley">
                            <input type="hidden" name="nmMatricula" value="${usuario.nrMatricula}"/>
                            <div class="columns30_70">
                                <div class="_30 alinhadoDireita">
                                    <label>Nome: </label>
                                </div>
                                <div class="_70">
                                    <input type="text" maxlength="300" data-required="true" style="width: 350px;" name="nome" value="${usuario.nome}"/><br/>
                                </div>
                            </div>
                            <div class="columns30_70">
                                <div class="_30 alinhadoDireita">
                                    <label>Email: </label>
                                </div>
                                <div class="_70">
                                    <input type="text" maxlength="300" data-type="email" data-required="true" style="width: 350px;" name="email" value="${usuario.email}"/><br/>
                                </div>
                            </div>
<!--                            <div class="columns30_70">
                                <div class="_30 alinhadoDireita">
                                    <label>Nº Matricula:</label>
                                </div>
                                <div class="_70">
                                    <input type="text" data-required="true" data-type="number" name="nMatricula" value=""/><br/>
                                </div>
                            </div>-->
                            <c:if test="${usuario.nrMatricula == null}">                              
                                <div class="columns30_70">
                                    <div class="_30 alinhadoDireita">   
                                            <label>Senha: </label>
                                    </div>
                                    <div class="_70">
                                        <input type="password" maxlength="30" data-required="true" name="senha" value="${usuario.senha}"/>
                                    </div>
                                </div>
                            </c:if>
                            <div class="columns30_70">
                                <div class="_30 alinhadoDireita">
                                    <label>Tipo de Usuário: </label><br/>
                                </div>
                                <div class="_70">
                                    <c:if test="${usuario.tpUsuario.id == 1}">
                                        <input type="radio" checked data-required="true" name="tipoUsuario" value="1"/>
                                        <label>Gerente</label><br/>
                                        <input type="radio" data-required="true" name="tipoUsuario" value="2"/>               
                                        <label>Técnico</label>
                                    </c:if>
                                    <c:if test="${usuario.tpUsuario.id != 1}">
                                        <input type="radio" data-required="true" name="tipoUsuario" value="1"/>
                                        <label>Gerente</label><br/>
                                        <input type="radio" checked data-required="true" name="tipoUsuario" value="2"/>               
                                        <label>Técnico</label>
                                    </c:if>
                                </div>
                            </div>
                            <div class="columns30_70"><div class="_30"></div>
                                <div class="_70">
                                    <input type="submit" onclick="if(!confirm('Confirma salvar este usuário?')) return false;" class="btnpqn" style="margin-left: 290px; width: 71px;" name="enviar" value="Salvar"/>
                                </div>
                            </div>
                        </form>
                    <table border="2" class="tabela alnCentro">
                            <thead>
                                <tr>
                                    <th>Nome</th>
                                    <th>Email</th>
                                    <th>Tipo de Usuario</th>
                                    <th>Alterar</th>
                                    <th>Excluir</th>
                                </tr>
                            </thead>
                            <tbody>
                                <c:if test="${listaUsuario != null}">
                                    <c:forEach var="usuario" items="${listaUsuario}">
                                        <tr>
                                            <td><c:out value="${usuario.nome}" /></td>
                                            <td><c:out value="${usuario.email}" /></td>
                                            <td><c:out value="${usuario.tpUsuario.nome}" /></td>
                                            <td> 
                                                <form method="POST" action="Controladora?action=BuscarUsuario">
                                                    <input type="hidden" name="idEdita" value="${usuario.nrMatricula}" />
                                                    <input type="image" src="images/ico_edit.png" id="edit"/>
                                                </form>
                                            </td>
                                            <td> 
                                                <form method="POST" action="Controladora?action=DeletarUsuario">
                                                    <input type="hidden" name="idDel" value="${usuario.nrMatricula}" />
                                                    <input type="image"onclick="if(!confirm('Tem certeza que deseja excluir o usuário?')) return false;" src="images/ico_del.png" id="edit"/>
                                                </form>
<!--                                        <a href='#'><img class='edit' src='images/ico_del.png'/> </a> -->
                                            </td>
                                        </tr>
                                    </c:forEach>
                                </c:if>
                            </tbody>
                        </table>
                </div>
            </div>
            
        <c:if test="${ msg != null }">
            <script type="text/javascript">
                var msg = '${msg}';
                alert(msg);
            </script>
        </c:if>
        <%@include file='footer.jsp' %>
    </div>
</html>
